#include "SmartCar.h"
#include <cstdlib>  // 用于生成随机数
#include <ctime>    // 用于初始化随机数种子

SmartCar::SmartCar() {
    model = "SCOUT MINI";
    wheelbase = 451;
    trackWidth = 490;
    clearance = 115;
    turningRadius = 0;
    driveType = "四轮四驱";
    maxRange = 10;
    tireType = "公路轮、麦克纳姆轮";
    tireSize = 175;
}

void SmartCar::generateCarID() {
    carID = "cqusn";
    for (int i = 0; i < 11; ++i) {
        if (rand() % 2 == 0) {
            carID += '0' + rand() % 10;  // 生成数字
        } else {
            carID += 'A' + rand() % 26;  // 生成字母
        }
    }
}

void SmartCar::generateChassisID() {
    chassisID = "dp";
    for (int i = 0; i < 6; ++i) {
        if (rand() % 2 == 0) {
            chassisID += '0' + rand() % 10;
        } else {
            chassisID += 'A' + rand() % 26;
        }
    }
}

void SmartCar::print() const {
    cout << "车辆编号: " << carID << endl;
    cout << "底盘编号: " << chassisID << endl;
    cout << "型号: " << model << endl;
    cout << "轴距: " << wheelbase << " mm" << endl;
    cout << "轮距: " << trackWidth << " mm" << endl;
    cout << "最小离地间隙: " << clearance << " mm" << endl;
    cout << "最小转弯半径: " << turningRadius << " m" << endl;
    cout << "驱动形式: " << driveType << endl;
    cout << "最大行程: " << maxRange << " KM" << endl;
    cout << "轮胎型号: " << tireType << endl;
    cout << "轮胎尺寸: " << tireSize << " mm" << endl;
}

void SmartCar::save(ofstream& outFile) const {
    outFile << carID << endl;
    outFile << chassisID << endl;
    outFile << model << endl;
    outFile << wheelbase << endl;
    outFile << trackWidth << endl;
    outFile << clearance << endl;
    outFile << turningRadius << endl;
    outFile << driveType << endl;
    outFile << maxRange << endl;
    outFile << tireType << endl;
    outFile << tireSize << endl;
}
